--[[=========================================================
	LOCALS
=========================================================]]--

--	Get player class
local PLAYER			= FindMetaTable( "Player" )

--[[=========================================================
	PLAYER FUNCTIONS
=========================================================]]--

--[[-----------------------------------------------------]]--
--	A server CVar has been changed
--[[-----------------------------------------------------]]--
function PLAYER:ServerCVarChanged( c, p, n )

	--	Initialize cvars list
	if not self.ServerVars then
		self.ServerVars		= {}
	end
	
	--	Save the value
	self.ServerVars[ c ]	= { Prev = p, Next = n }

end

--[[=========================================================
	HELPER FUNCTIONS
=========================================================]]--

--[[-----------------------------------------------------]]--
--	Get a player by nick
--[[-----------------------------------------------------]]--
player.GetByNick = function( nick, ... )

	--	Should return all matching players ?
	local allMatches = select( 1, ... )

	--	Get all players
	local players = player.GetAll()
	
	--	Loop players
	local matches = {}
	for i,ply in ipairs(players) do
	
		--	Check if the player's nick contains the given string
		if string.match( ply:Nick(), nick ) then
		
			--	If we want all matches, add it to the list
			if allMatches then
				table.insert( matches, ply )
			
			--	Otherwise, immediately return the found player
			else
				return ply
			end
		end
	end
	
	/* Return all matches found */
	return matches
end

--[[-----------------------------------------------------]]--
--	Get by steam ID
--[[-----------------------------------------------------]]--
player.GetBySteamID = function( steamID )

	--	Get all players
	local players = player.GetAll()
	
	--	Loop players
	for i,ply in ipairs(players) do
	
		--	Check if the player's steam ID is the same as the given one
		if ply:SteamID() == steamID then
			return ply
		end
	end
	
	--	If not found, return false
	return false
end

--[[-----------------------------------------------------]]--
--	Checks whether a player is valid or not
--[[-----------------------------------------------------]]--
player.IsValid = function( ply )	
	return ply and type( ply ) == "Player" and IsValid( ply ) and ply:IsPlayer()
end

--[[=========================================================
	INPUT
=========================================================]]--

--[[-----------------------------------------------------]]--
--	Registers accessors for common actions
--[[-----------------------------------------------------]]--
AccessorFuncIN( PLAYER, IN_RUN, "Running" )
AccessorFuncIN( PLAYER, IN_SPEED, "Running" )
AccessorFuncIN( PLAYER, IN_WALK, "Walking" )
AccessorFuncIN( PLAYER, IN_MOVELEFT, "MovingLeft" )
AccessorFuncIN( PLAYER, IN_MOVERIGHT, "MovingRight" )
AccessorFuncIN( PLAYER, IN_BACK, "MovingBack" )
AccessorFuncIN( PLAYER, IN_FORWARD, "MovingForward" )